package com.mypro.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

public class MySessionFactory {
    public static SqlSession getSession(){
        Reader reader = null;//加载主配置文件
        try {
            reader = Resources.getResourceAsReader("configuration.xml");
            SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
            SqlSessionFactory factory = builder.build(reader);
            SqlSession  session = factory.openSession();
            return session;
        } catch (IOException e) {
            e.printStackTrace();
        }

        return  null;
    }
}
